package com.kantboot.file.controller;

import com.kantboot.file.entity.CesImage;
import com.kantboot.file.entity.CesVideo;
import com.kantboot.file.service.CesVideoService;
import com.kantboot.util.RestResult;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/file/ces-video")
public class CesVideoController {

    @Resource
    private CesVideoService cesVideoService;

    /**
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/upload", method = RequestMethod.POST, consumes = "multipart/form-data")
    public RestResult<CesVideo> add(
            @RequestParam("video") MultipartFile video) throws IOException {
        return RestResult.success(cesVideoService.uploadVideo(video), "添加成功");
    }

    @SneakyThrows
    @RequestMapping("/view/{id}")
    public void viewImage(@PathVariable("id") Integer id, HttpServletResponse response) {
        cesVideoService.showVideoById(id,response);
    }
}
